package com.xpqh.ksg.modular.users.service;

import com.xpqh.ksg.common.persistence.dao.KsgUserNoticeMapper;
import com.xpqh.ksg.common.persistence.dao.KsgUsersMapper;
import com.xpqh.ksg.common.persistence.model.KsgUsers;
import com.xpqh.ksg.modular.users.dto.KsgUserUpdateReqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class KsgUsersService {

    @Autowired
    private KsgUsersMapper ksgUsersMapper;

    @Autowired
    private KsgUserNoticeMapper ksgUserNoticeMapper;
    public KsgUsers get(Integer userId) {
        Integer unReadCount = ksgUserNoticeMapper.getUserUnReadCount(userId);
        KsgUsers KsgUsers = ksgUsersMapper.selectById(userId);
        KsgUsers.setUnReadMsgCount(unReadCount);
        KsgUsers.setIsAdmin(ksgUsersMapper.isAdmin(KsgUsers.getPhone()));
        return KsgUsers;
    }

    public boolean updateUserInfo(KsgUserUpdateReqDTO reqDTO, int userId) {
        KsgUsers KsgUsers = ksgUsersMapper.selectById(userId);
        KsgUsers.setUserName(reqDTO.getUserName());
        KsgUsers.setHeadImg(reqDTO.getAvatarUrl());
        ksgUsersMapper.updateById(KsgUsers);
        return true;
    }
}


